﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Collections.ObjectModel;
using System.Xml.Serialization;

namespace BusinessObjects
{
    /// <summary>
    /// The absolute event !
    /// </summary>
    [DataContract]    
    public class Event : BaseBusinessObject
    {
        private string image;
        private string description;
        private bool isLocked;
        private RegionObjectTypes type;
        private string title;
        private int requiredMembersCount;

        private List<UserBadge> requiredBadges;
        private List<int> requiredBadgesIds;

        public int PlayerId
        {
            get;
            set;
        }

        public int MapId
        {
            get;
            set;
        }

        public string Image
        {
            get
            {
                return this.image;
            }
            set
            {
                if ( this.image == value )
                    return;

                this.image = value;
                this.NotifyPropertyChanged( "Image" );
            }
        }

        public string Title
        {
            get
            {
                return this.title;
            }
            set
            {
                if ( this.title == value )
                    return;

                this.title = value;
                this.NotifyPropertyChanged( "Title" );
            }
        }

        public string Description
        {
            get
            {
                return this.description;
            }
            set
            {
                if ( this.description == value )
                    return;

                this.description = value;
                this.NotifyPropertyChanged( "Description" );
            }
        }

        public bool IsLocked
        {
            get
            {
                return this.isLocked;
            }
            set
            {
                if ( this.isLocked == value )
                    return;

                this.isLocked = value;
                this.NotifyPropertyChanged( "IsLocked" );
            }
        }

        public RegionObjectTypes Type
        {
            get
            {
                return this.type;
            }
            set
            {
                if ( this.type == value )
                    return;

                this.type = value;
                this.NotifyPropertyChanged( "Type" );
            }
        }
                
        public List<int> RequiredBadgesIds
        {
            get
            {
                if ( this.requiredBadgesIds == null )
                    this.requiredBadgesIds = new List<int>();

                return this.requiredBadgesIds;
            }
            set
            {
                if ( this.requiredBadgesIds == value )
                    return;

                this.requiredBadgesIds = value;
                this.NotifyPropertyChanged( "RequiredBadgesIds" );
            }
        }

        public int RequiredMembersCount
        {
            get
            {
                return this.requiredMembersCount;
            }
            set
            {
                if ( this.requiredMembersCount == value )
                    return;

                this.requiredMembersCount = value;
                this.NotifyPropertyChanged( "RequiredMembersCount" );
            }
        }

        [XmlIgnore]
        public List<UserBadge> RequiredBadges
        {
            get
            {
                if ( this.requiredBadges == null )
                    this.requiredBadges = new List<UserBadge>();

                return this.requiredBadges;
            }
            set
            {
                if ( this.requiredBadges == value )
                    return;

                this.requiredBadges = value;
                this.NotifyPropertyChanged( "RequiredBadges" );
            }
        }

        public bool IsSingleInitiated
        {
            get;
            set;
        }

        public bool IsBuild
        {
            get;
            set;
        }
        
        public override object Clone()
        {
            Event clone = new Event() 
            {
                Image = this.Image,
                Title = this.Title,
                Description = this.Description,
                Type = this.Type,
                RequiredMembersCount = this.RequiredMembersCount,
                IsSingleInitiated = this.IsSingleInitiated,
                IsBuild = this.IsBuild
            };

            foreach ( UserBadge ub in this.RequiredBadges )
                clone.RequiredBadges.Add(ub.Clone() as UserBadge);

            foreach ( int id in this.RequiredBadgesIds )
                clone.RequiredBadgesIds.Add( id );

            return clone;
        }
    }
}
